<?php
namespace app\admin\controller;
use app\common\controller\AdminBase;

/* 通电柜模式 */
class CommonCabinet extends  AdminBase
{
	protected $beforeActionList = [
        'before_index'=>['only'=>'index'],
    ];
	function _initialize() {
		parent::_initialize();				
    }
	
	function index(){
		echo $this->fetch();
	}
	
	/*员工列表数据*/
	function ajax_index(){
		$this->ajax($this->_ajax_index());
	}
	/**
	 * 新增记录
	 * */
	function  addPost(){
		$card_no=input("card_no");
		$admin=sp_get_current_admin();
		db("CommonCabinetLog")->insert(array("card_no"=>$card_no,"admin_id"=>$admin["id"],"admin_name"=>$admin['name'],"admin_account"=>$admin['account'],"admin_mobile"=>$admin['mobile'],"shop_id"=>$admin['shop_id']));
		$this->ajax_success("成功");
	}
	/**
	 * 权限菜单
	 **/
	function before_index(){
		$auth_group=sp_get_auth_menu_3("10041022");
		$this->assign("menus",$auth_group);
	}
	
	/*获取员工数据*/
	private function _ajax_index(){
		$query=array(
					 'admin_name'=>array("field" =>"admin_name","operator" =>"like"),
					 'admin_account'=>array("field" =>"admin_account","operator" =>"like"),
					 );
		$draw=input("draw",0)+1;//请求时间		 
		$where_and=join(" and ",sp_get_param_sql(request()->isPost(),$query));
		$shop_id=sp_get_current_shop_id();
		$where_and.=" and shop_id=$shop_id";
		$total=db("CommonCabinetLog")->where($where_and)->fetchsql(FALSE)->count(1);
		$list=db("CommonCabinetLog")->where($where_and)->order($this->get_order())->limit($this->get_limit())->fetchsql(FALSE)->select();
		return array('pageData'=>$list,'total'=>$total,"draw"=>$draw);
	}
	
}
